using System.Data;
using System;
using Library.Business;
using NhatThanhSoftware;
namespace Library.Controller
{
    public partial class Controller_ThongTinGia: Cls_ThongTinGia
    {
        /// <summary>
        /// Set du lieu
        /// </summary>
        private static void setThongTinGia(ref Cls_ThongTinGia ThongTinGia, DataRow dr)
        {
            ThongTinGia.ID_HeThongNuoc = dr[Cls_ThongTinGia.fn_ID_HeThongNuoc].ToString() ;
            ThongTinGia.Thang = Convert.ToInt32(dr[Cls_ThongTinGia.fn_Thang] ) ;
            ThongTinGia.Nam = Convert.ToInt32(dr[Cls_ThongTinGia.fn_Nam] ) ;
            ThongTinGia.Hidden = Convert.ToBoolean(dr[Cls_ThongTinGia.fn_Hidden] ) ;
        }
        /// <summary>
        /// Lưu dữ liệu
        /// </summary>
        /// <param name="dtData">Datatable</param>
        /// <returns>TRUE;FALSE</returns>
        public static bool doSAVE(DataTable dtData)
        {
            if (dtData.GetChanges() == null) return false;
            foreach( DataRow dr in dtData.GetChanges().Rows )
            {
                Cls_ThongTinGia ThongTinGia = new Cls_ThongTinGia();
                try
                {
                    switch(dr.RowState)
                    {
                        case DataRowState.Modified:
                            setThongTinGia(ref ThongTinGia, dr);
                            ThongTinGia.ID_ThongTinGia_find =Convert.ToInt32(dr[Cls_ThongTinGia.fn_ID_ThongTinGia] );
                            ThongTinGia.ID_ThongTinGia=ThongTinGia.ID_ThongTinGia_find;
                            ThongTinGia.doUpdate();
                            break;
                        case DataRowState.Added:
                            setThongTinGia(ref ThongTinGia, dr);
                            ThongTinGia.doInsert();
                            break;
                        case DataRowState.Deleted:
                            ThongTinGia.ID_ThongTinGia_find =Convert.ToInt32(dr[Cls_ThongTinGia.fn_ID_ThongTinGia, DataRowVersion.Original] );
                            ThongTinGia.doDelete();
                            break;
                    }
                }
                catch (Exception ex)
                {
                    ThongBao.msgThongBao(ThongTinGia.ID_ThongTinGia + " chưa lưu được, click nút [OK] để lưu tiếp.");
                }
        }
        return true;
        }
        /// <summary>
        /// Check dữ liệu
        /// </summary>
        /// <param name="dtData">Datatable</param>
        /// <returns>TRUE;FALSE</returns>}
        public static void doCHECK(DataTable dtData)
        {
            if (dtData.GetChanges() == null) return;
            DataRowCollection drColection = dtData.GetChanges().Rows;
            foreach (DataRow dr in drColection)
            {
                if (dr.RowState == DataRowState.Deleted) break;
                string strID_ThongTinGia = dr[Cls_ThongTinGia.fn_ID_ThongTinGia].ToString();
                if (dr.RowState == DataRowState.Added)
                {
                }
            }
        }
    }
}
